﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiSha.Entity.OrganizationManage;
using YiSha.Entity.RedBookFormManage;
using YiSha.Entity.RedBookSetManage;
using YiSha.Model.Param.RedBookFormManage;
using YiSha.Model.Param.RedBookSetManage;
using YiSha.Service.OrganizationManage;
using YiSha.Service.RedBookFormManage;
using YiSha.Service.RedBookSetManage;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;
using YiSha.Web.Code;

namespace YiSha.Business.RedBookFormManage
{
    public class RedBookFormBll
    {
        private RedBookFormService redBookFormService = new RedBookFormService();
        private UserService userService = new UserService();

        #region 获取数据
        public async Task<TData<List<RedBookFormEntity>>> GetList(RedBookFormParam param)
        {
            TData<List<RedBookFormEntity>> obj = new TData<List<RedBookFormEntity>>();
            obj.Data = await redBookFormService.GetList(param);
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<RedBookFormEntity>>> GetPageList(RedBookFormParam param, Pagination pagination)
        {
            TData<List<RedBookFormEntity>> obj = new TData<List<RedBookFormEntity>>();


            OperatorInfo operatorInfo = await Operator.Instance.Current();
            if (!string.IsNullOrEmpty(operatorInfo.RoleNames) && operatorInfo.RoleNames.Contains("管理员"))
            {
            }
            else   //用户角色只能看到自己的
            { 
                param.CurrentUserId = operatorInfo.UserId;
            }
       
            obj.Data = await redBookFormService.GetPageList(param, pagination);
           
        
            obj.Total = pagination.TotalCount;
            obj.Tag = 1;
          
            return obj;
        }
        public async Task<TData<RedBookFormEntity>> GetEntity(long id)
        {
            TData<RedBookFormEntity> obj = new TData<RedBookFormEntity>();
            RedBookFormEntity redBookFormEntity = await redBookFormService.GetEntity(id);
            obj.Data = redBookFormEntity;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<int>> GetMaxSort()
        {
            TData<int> obj = new TData<int>();
            obj.Data = await redBookFormService.GetMaxSort();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<SelectData>>> GetUserDataList()
        {
            TData<List<SelectData>> obj = new TData<List<SelectData>>();
            obj.Data = await redBookFormService.GetUserDataList();
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 提交数据
        public async Task<TData<string>> SaveForm(RedBookFormEntity entity)
        {
            TData<string> obj = new TData<string>();
        
            await redBookFormService.SaveForm(entity);
            obj.Data = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData> DeleteForm(string ids)
        {
            TData obj = new TData();
            await redBookFormService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion
    }
}
